package com.hong.jarlauncher;

import javax.swing.*;
import java.awt.*;

import javax.swing.*;
import java.awt.*;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
import java.awt.*;

public class MainFrame extends JFrame {
    private boolean darkTheme = false;

    public MainFrame() {
        setTitle("JAR 启动器");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(1000, 600);
        setLocationRelativeTo(null);

        JPanel mainPanel = new JPanel(new BorderLayout());

        TabbedPane tabbedPane = new TabbedPane();
        mainPanel.add(tabbedPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

        JButton globalThemeButton = new JButton("切换全局主题");
        globalThemeButton.addActionListener(e -> toggleGlobalTheme());
        buttonPanel.add(globalThemeButton);

        JButton addTabButton = new JButton("添加服务");
        addTabButton.addActionListener(e -> tabbedPane.addNewServiceTab());
        buttonPanel.add(addTabButton);

        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        add(mainPanel);
    }

    private void toggleGlobalTheme() {
        darkTheme = !darkTheme;
        try {
            if (darkTheme) {
                UIManager.setLookAndFeel(new FlatDarkLaf());
            } else {
                UIManager.setLookAndFeel(new FlatLightLaf());
            }
            SwingUtilities.updateComponentTreeUI(this);
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }
}